#pragma once
//============================================================================
// Copyright (C) 2003-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================


//RcSysPktFindServers flags
#define RC_SYS_PKT_FIND_NODE_RESERVED_TRACKER_FLAG		0x80000000
#define RC_SYS_PKT_FIND_NODE_HAS_NICKNAME				0x40000000		//has nickname
#define RC_SYS_PKT_FIND_NODE_HAS_TC_PLUGIN_NAME			0x20000000		//has group name
#define RC_SYS_PKT_FIND_NODE_HAS_DESC					0x10000000		//has description
#define RC_SYS_PKT_FIND_NODE_HAS_KEY_INFO				0x08000000		//has public encryption key
//#define RC_SYS_PKT_FIND_NODE_IP_NOT_SAME					0x04000000		//ip in packet not the same as ip recieved from

#define RC_SYS_PKT_FIND_NODE_MUST_MATCH_ALL				0x04000000  //if set only return servers that match all services


#define RC_SYS_PKT_FIND_NODE_PHOTO_FILES_AVAIL			0x00000001		
#define RC_SYS_PKT_FIND_NODE_AUDIO_FILES_AVAIL			0x00000002
#define RC_SYS_PKT_FIND_NODE_VIDEO_FILES_AVAIL			0x00000004
#define RC_SYS_PKT_FIND_NODE_PROGRAM_FILES_AVAIL		0x00000008
#define RC_SYS_PKT_FIND_NODE_ARCHIVE_FILES_AVAIL		0x00000010
#define RC_SYS_PKT_FIND_NODE_OTHER_FILES_AVAIL			0x00000020

#define RC_SYS_PKT_FIND_NODE_INSTANT_MSG_AVAIL				0x00000040		
#define RC_SYS_PKT_FIND_NODE_VOICE_AVAIL					0x00000080		
#define RC_SYS_PKT_FIND_NODE_VIDEO_AVAIL					0x00000100		
#define RC_SYS_PKT_FIND_NODE_WEB_PAGE_AVAIL					0x00000200		
#define RC_SYS_PKT_FIND_NODE_WEB_CAM_SERVER_AVAIL			0x00000400		
#define RC_SYS_PKT_FIND_NODE_TEXT_CHAT_ROOM_SERVER_AVAIL	0x00000800		
#define RC_SYS_PKT_FIND_NODE_BILLIARDS_AVAIL				0x00001000		
#define RC_SYS_PKT_FIND_NODE_FILE_SHARE_AVAIL				0x00002000		
#define RC_SYS_PKT_FIND_NODE_3D_CHAT_ROOM_SERVER_AVAIL		0x00004000

//RcSysPktAnnounce defines
#define RC_SYS_PKT_FIND_NODE_MAX_NAME_LEN		15
#define RC_SYS_PKT_FIND_NODE_MAX_KEY_LEN		128 //max length of key in bytes not bits

#pragma pack(push) 
#pragma pack(1)
class RcSysPktFindNode : public RcSysPktHdr
{
public:
	U8 * GetKey( void );

	
	//=== constructor/destructor ===//
	RcSysPktFindNode()
		: m_u16Version( 1 )
		, m_u16Reason( 0 )
		, m_u32Flags( 0 )
		, m_u16UplinkSpeed( 0 )
		, m_u16DnlinkSpeed( 0 )
		, m_u16PluginFlags( 0 )
		, m_u8MatchType( 0 )
		, m_u8Ttl( 1 )
		, m_s64FileByteCntQuota( 0 )
		, m_u16FileUplinkQuota( 0 )
	{
		m_u16PktType = RC_SYS_PKT_TYPE_FIND_NODE;
		m_u16PktLen = (U16)EmptyLen();
	}

	//=== note: allways call  AddNickName then AddGroupName then AddKey ===//
	void	AddNickName( const char * pName );
	void	AddNickName( std::string &csName );
	void	AddDesc( const char * pDesc );
	void	AddDesc( std::string &csDesc );
	void	AddPluginName( std::string &csName );
	void	AddKey( U8 * pu8Key );//note: first byte of key is the key length in bytes + 1
	void	CalcLen( void );//call after all items have been added
	void	GetNickName( std::string &csName );
	void	GetDesc( std::string &csDesc );
	void	GetPluginName( std::string &csName );
	U32		EmptyLen( void ){ return sizeof( RcSysPktFindNode ) - sizeof( m_au8Additional ); }

	//=== vars ===//
	U16				m_u16Version;
	U16				m_u16Reason;
	U32				m_u32Flags;
	U16				m_u16UplinkSpeed;	//speed of uplink to internet  
	U16				m_u16DnlinkSpeed;	//speed of dnlink from internet
	U16				m_u16PluginFlags;
	U8				m_u8MatchType;
	U8				m_u8Ttl;
	S64				m_s64FileByteCntQuota;
	U16				m_u16FileUplinkQuota;

	U8				m_au8Additional[ ((RC_SYS_PKT_FIND_NODE_MAX_NAME_LEN + 1) * 2) + RC_SYS_PKT_FIND_NODE_MAX_KEY_LEN ];
};
#pragma pack(pop)

//make m_u16RcSysPktType RC_SYS_PKT_TYPE_FIND_NODE if asking trackers for servers that match




